package com.yubest.designpattern.struct.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂
 *
 * @Author: hweiyu
 * @Date: 2022/10/26 15:14
 */
public class FlyweightFactory {

    private Map<Integer, Flyweight> map = new HashMap<>();

    public Flyweight get(Integer id) {
        if (!map.containsKey(id)) {
            Flyweight flyweight = new Flyweight(id);
            map.put(id, flyweight);
        }
        return map.get(id);
    }
}
